package com.lin.manager.oss.web;

import com.lin.manager.common.resp.R;
import com.lin.manager.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @作者: 林江
 * @创建时间: 2024/3/21
 * @功能:
 */
@Api(tags = "文件管理")
@RestController
@RequestMapping("/file")
public class OssController {
    @Resource
    private OssService ossService;

    @ApiOperation("文件管理 - oss文件上传")
    @PostMapping("uploadOss")
    public R uploadOss(MultipartFile file) throws Exception {
        ossService.upload(file);
        return R.ok();
    }

    @ApiOperation("文件管理 - oss文件下载")
    @GetMapping("downloadOss")
    public void downloadOss(HttpServletResponse response,
                            String objectName) throws Exception {
        ossService.download(objectName);
    }
}
